#-*- coding:utf-8 -*-

from django.db import models
from django.db import models
from django.contrib.auth.models import User
from django.contrib.sites.models import Site


class Article(models.Model):
    author = models.ForeignKey(User)
    site = models.ForeignKey(Site)
    bigtype = models.PositiveIntegerField()
    typeid = models.PositiveIntegerField()
    title = models.CharField(max_length=100)
    content = models.TextField(max_length=4096)
    exdata = models.TextField(blank=True) # extandable fields
    posttime = models.DateTimeField(auto_now=True)

    zans = models.PositiveIntegerField(default=0)
    saves = models.PositiveIntegerField(default=0)
    reads = models.PositiveIntegerField(default=0)
    comments = models.PositiveIntegerField(default=0)

    status = models.PositiveIntegerField(default=0)
    allowcomment = models.BooleanField(default=True)

    isetop = models.BooleanField(default=False) 
    topexpire = models.DateTimeField(auto_now=True)
    lastupdate = models.DateTimeField(auto_now=True) 

    groupf1 = models.PositiveIntegerField(default=0) 
    groupf2= models.PositiveIntegerField(default=0)
    groupf3= models.PositiveIntegerField(default=0)

    def __unicode__(self):
        return self.title


class Comment(models.Model):
    author = models.ForeignKey(User)
    article = models.ForeignKey(Article)
    content = models.TextField(max_length=1024)
    posttime = models.DateTimeField(auto_now=True)
    
    def __unicode__(self):
        return self.content


SUPPORT_ZAN  = 1
SUPPORT_SAVE = 2
class SupportArt(models.Model):
    user = models.ForeignKey(User)
    article = models.ForeignKey(Article)
    ts = models.DateTimeField(auto_now=True)
    tag = models.PositiveIntegerField(default=0)


class TopShow(models.Model):
    article = models.ForeignKey(Article)
    typeid = models.PositiveIntegerField()
    askdate = models.DateTimeField()
    effect_begin = models.DateTimeField()
    effect_end = models.DateTimeField()


class AskPrice(models.Model):
    user = models.ForeignKey(User)
    article = models.ForeignKey(Article)
    typeid = models.PositiveIntegerField()
    price = models.PositiveIntegerField()


class Group(models.Model):
    site = models.ForeignKey(Site)
    owner = models.ForeignKey(User)
    gtype = models.PositiveIntegerField()
    name = models.CharField(max_length=100)
    logo = models.CharField(max_length=200)
    desc = models.CharField(max_length=1024)
    createdate = models.DateTimeField(auto_now=True)
    status = models.PositiveIntegerField()

    def __unicode__(self):
        return self.name


class GroupMember(models.Model):
    user = models.ForeignKey(User)
    group = models.ForeignKey(Group)
    status = models.PositiveIntegerField(default=0)
    ts0 = models.DateTimeField()
    ts1 = models.DateTimeField()


class Message(models.Model):
    sender= models.ForeignKey(User, related_name="sender")
    receiver= models.ForeignKey(User, related_name="receiver")
    sendtime = models.DateTimeField(auto_now=True)
    fromdel = models.BooleanField(default=False)
    todel = models.BooleanField(default=False)


class UserImage(models.Model):
    user = models.ForeignKey(User)
    article = models.ForeignKey(Article, null=True, blank=True)
    image = models.ImageField(upload_to="images", null=True, blank=True)
    path = models.CharField(max_length=128)
    size = models.PositiveIntegerField(default=0)
    width = models.PositiveIntegerField(default=0)
    height = models.PositiveIntegerField(default=0)
    uptime = models.DateTimeField(auto_now=True)

